package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.annotation.ManageLogAnnotation;
import com.wanmait.wanmarecruit.entity.Recruiter;
import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.mapper.RecruiterMapper;
import com.wanmait.wanmarecruit.service.RecruiterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(rollbackFor = Exception.class)
public class RecruiterServiceImpl extends ServiceImpl<RecruiterMapper, Recruiter> implements RecruiterService {

    @Resource
    private RecruiterMapper recruiterMapper;

    @Override
    public void changePassword(Recruiter recruiter) {
        LambdaUpdateWrapper<Recruiter> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Recruiter::getPhone,recruiter.getPhone());
        this.update(recruiter,updateWrapper);
    }

    @Override
    public Recruiter LoginOrNots(Recruiter recruiter) {
        LambdaQueryWrapper<Recruiter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(recruiter.getPhone()!=null,Recruiter::getPhone,recruiter.getPhone());
        queryWrapper.eq(recruiter.getPass()!=null,Recruiter::getPass,recruiter.getPass());
        Recruiter recruiters = recruiterMapper.selectOne(queryWrapper);
        return recruiters;
    }

    @Override
    public Recruiter companySignIn(Recruiter recruiter) {
        LambdaQueryWrapper<Recruiter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(recruiter.getPhone()!=null,Recruiter::getPhone,recruiter.getPhone());
        queryWrapper.eq(recruiter.getPass()!=null,Recruiter::getPass,recruiter.getPass());
        Recruiter recruiters = recruiterMapper.selectOne(queryWrapper);
        return recruiters;
    }

    @Override
    public Boolean verifyCompanySignUp(String memPhone) {
        LambdaQueryWrapper<Recruiter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(memPhone!=null,Recruiter::getPhone,memPhone);
        Recruiter recruiter = recruiterMapper.selectOne(queryWrapper);
        return recruiter != null;
    }

    @Override
    public void updateNotEnableRecruitInfo(Recruiter recruiter) {
        recruiterMapper.updateNotEnableRecruitInfo(recruiter);
    }

    @Override
    public PageInfo<Recruiter> getAllHrMessageList(Integer pageNum, Integer pageSize, String keyword, Integer positionTypeId) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(recruiterMapper.seletAllRecruiterMessage(keyword, positionTypeId));
    }

    @Override
    @ManageLogAnnotation(module = "招聘者管理",info = "已经该招聘者封禁")
    public void updateHrEnableById(Integer recruiterId) {
        UpdateWrapper<Recruiter> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("enable",0).in("id",recruiterId);
        this.update(updateWrapper);
    }

    @Override
    public Long getRecruiterCount() {
        return this.count();
    }
}
